import scrapy
from scrapy.spiders import Spider,CrawlSpider,XMLFeedSpider,CSVFeedSpider,SitemapSpider

class AuthorSpider(scrapy.Spider):
	name = 'author'
	# allowed_domains = ['quotes.com']
	start_urls = ['http://quotes.toscrape.com/']
	
	def parse(self, response):
		page_links = response.css('.author + a')
		yield from response.follow_all(page_links, self.parse_author)
		page_next = response.css('li.next a')
		yield from response.follow_all(page_next, self.parse)
	
	def parse_author(self, response):
		def extract_with_css(query):
			return response.css(query).get(default='').strip()
		
		yield {
			'name': extract_with_css('h3.author-title::text'),
			'birthdate': extract_with_css('.author-born-date::text'),
			'bio': extract_with_css('.author-description::text'),
		}
